package util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtils {

	static Properties properties = new Properties();
	static InputStream inputStream = null;
	static {
		try {
			inputStream = new FileInputStream(new File("lexer\\resources\\init-word.properties"));
			properties.load(inputStream);
		} catch (FileNotFoundException e) {
//			e.printStackTrace();
			throw new RuntimeException("读取配置文件出错");
		} catch (IOException e) {
//			e.printStackTrace();
			throw new RuntimeException("初始化配置文件异常");
		} finally {
			if(inputStream != null)
				try {
					inputStream.close();
				} catch (IOException e) {
					throw new RuntimeException("初始化配置文件异常");
				}
		}
		
	}
	
	public static String getValue(String key) {
		String value = properties.getProperty(key);
		if(value == null || "".equals(value.trim())) throw new IllegalArgumentException("非法的key: " + key);
		return value;
	}
	
	public static void main(String[] args) {
		System.out.println(getValue("keyword"));
	}
}
